package com.wcj.select;

public class 二分查找 {
    public static int BinarySearchIterative(int a[],int n,int data){
        int low = 0;
        int high = n - 1;
        while (low <= high){
            int mid = low + (high - low)/2;
            if (a[mid] == data){
                return mid;
            }else if (a[mid] < data){
                low = mid + 1;
            }else {
                high = mid - 1;
            }
        }
        return -1;
    }
}
